using System;
using System.Linq;
using System.Collections.Generic;
using CodeMinder.Output.Interface;
using CodeMinder.SCM.Interface;
using NUnit.Framework;
using Rhino.Mocks;

namespace CodeMinder.Core.Tests
{
    [TestFixture]
    public class GraphCreatorTests
    {
        private IGraphOutput _outputSource;
        private ISourceControlProvider _inputSource;

        private List<ISourceControlProvider> _inputSources;
        private GraphCreator _graphCreator;

        [SetUp]
        public void Setup()
        {
            _outputSource = MockRepository.GenerateMock<IGraphOutput>();
            _inputSource = MockRepository.GenerateMock<ISourceControlProvider>();
            _inputSources = new List<ISourceControlProvider> {_inputSource};
            
            _graphCreator = new GraphCreator(_inputSources, _outputSource);
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void Ctor_WhenSourceNull_Throw()
        {
            var gc = new GraphCreator(null, _outputSource);
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void Ctor_WhenSourceListIsEmpty_Throw()
        {
            var gc = new GraphCreator(new ISourceControlProvider[0], _outputSource);
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void Ctor_WhenOutputIsNull_Throw()
        {
            var gc = new GraphCreator(_inputSources, null);
        }

        [Test]
        public void when_none_of_the_sources_exist_return_false()
        {
            _inputSource.Stub(i => i.IsValid).Return(false);
            Assert.That(_graphCreator.TryCreate(), Is.False);
        }

        [Test]
        public void when_some_of_the_sources_exist_return_true()
        {
            var anotherInputSource = MockRepository.GenerateMock<ISourceControlProvider>();
            anotherInputSource.Stub(i => i.IsValid).Return(true);
            _inputSources.Add(anotherInputSource);
            _inputSource.Stub(i => i.IsValid).Return(false);

            Assert.That(_graphCreator.TryCreate(), Is.True);
        }

        [Test]
        public void when_multiple_sources_exist()
        {
            
        }
    }
}